function [stock_id, all_ret_predicted, all_ret_real, all_prices_clo,...
    all_prices_hi, all_prices_lo, all_dates_ret, data_FA] = ...
    ...
    prepare_variables(ticker, from_time, to_time, normalize_type,...
    y_in, y_out, time_lag, gap_ret, tool_FA, hiddenLayerSize_FA, ...
    gap_TA, window, tool_TA, hiddenLayerSize_TA)
  
stock_id = get_info_from_database('sec_id', ticker);
data_1stock = get_FI_from_security(stock_id,from_time,to_time);

[data_FA, ~, ~] = ...
    normalize_data(data_1stock, normalize_type, stock_id, ...
    y_in, y_out, time_lag, 1, 1);

quar_all = data_FA(:,3);

all_ret_predicted = [];
all_ret_real = [];
all_prices_clo = [];
all_prices_hi = [];
all_prices_lo = [];
all_dates_ret = [];

%-----------------------------------
for i = 1:size(quar_all,1) - y_in + 1
% for i = 1
    fprintf('Processing %d / %d\n',i, size(quar_all,1)-y_in+1)
    data_FA_in = data_FA(i:i+y_in-1,:);
    % We have to take into account the lag_time in FA data
    data_FA_out = data_FA(i+y_in-time_lag : i+y_in+y_out-1-time_lag,:);
    
    result = get_info_from_database('security-info', data_FA(1,1));
    sector_id = result.sector_id;
    
    all_sec_id_ok = get_sec_in_same_sector(sector_id);
    sub_sec_id_ok = all_sec_id_ok(1:end,1);
    
    fromTime = data_FA(i,2)*10 + data_FA(i,3);
    toTime = data_FA(i+y_in-1,2)*10 + data_FA(i+y_in-1,3);
    
    dataX = get_FI(sub_sec_id_ok,fromTime,toTime);

    [dataX_normalize, data_fa_in, data_fa_out] = ...
    normalize_data(dataX, normalize_type, stock_id, ...
    y_in, y_out, time_lag, data_FA_in, data_FA_out);

    [mat_X_FA, mat_Y_FA, mat_Y_FA_vol] = ...
        prepare_FA(dataX_normalize,gap_ret,time_lag);
    
    if strcmp(tool_FA, 'NN') == 1
        net = predict_return(tool_FA,mat_X_FA,mat_Y_FA,...
            hiddenLayerSize_FA);
        
        ret_FA_in = net(data_fa_in')';
        ret_FA_out = net(data_fa_out')';
    else
        [coeff, inmodel] = predict_return(tool_FA,mat_X_FA,mat_Y_FA,...
            hiddenLayerSize_FA);
        
        ret_FA_in = data_fa_in(:,inmodel) * coeff(inmodel)';
        ret_FA_out = data_fa_out(:,inmodel) * coeff(inmodel)';
    end
    
    % Return the TA and returns in the in-sample
    [mat_X_TA, mat_Y_TA,~,~,~,~,~] = prepare_TA(stock_id, data_FA_in,...
        ret_FA_in, gap_TA, gap_ret, window, time_lag);
    
    % Return the technical indicators in out sample mat_X_TA_out
    [mat_X_TA_out, residual, ret_real, price_clo, price_hi,...
        price_lo, dates_ret] = prepare_TA(stock_id, data_FA_out,...
        ret_FA_out, gap_TA, gap_ret, window, time_lag);
    
    ret_FA_out_all = ret_real - residual;
    
    mat_X_TA = mat_X_TA(:,[1:3,6:8,11:end]);
    mat_X_TA_out = mat_X_TA_out(:,[1:3,6:8,11:end]);
    
    if strcmp(tool_TA, 'NN') == 1
        net = predict_return(tool_TA,mat_X_TA,...
            mat_Y_TA,hiddenLayerSize_TA);
        
        residual_TA = net(mat_X_TA_out')';
    else
        [coeff , inmodel] = predict_return(tool_TA,...
            mat_X_TA,mat_Y_TA,hiddenLayerSize_TA);
        
        residual_TA = mat_X_TA_out(:,inmodel)...
            * coeff(inmodel)';
    end
    
    ret_predicted = ret_FA_out + residual_TA;
    
    all_ret_predicted = [all_ret_predicted ; ret_predicted];
    all_ret_real = [all_ret_real ; ret_real];
    
    all_prices_clo = [all_prices_clo ; price_clo];
    all_prices_hi = [all_prices_hi ; price_hi];
    all_prices_lo = [all_prices_lo ; price_lo];
    all_dates_ret = [all_dates_ret ; dates_ret];

    nntraintool('close')
        
end
end